package com.yutel.multher;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yutel.multher.reaper.ReaperServer;
import com.yutel.multher.reaper.domain.TaskData;
import com.yutel.multher.reaper.exception.ReaperException;
import com.yutel.multher.reaper.listener.OnAutoListener;
import com.yutel.multher.reaper.listener.OnDataListener;
import com.yutel.multher.reaper.listener.OnTaskListener;

public class App {
	private static final Logger log = LoggerFactory.getLogger(App.class);

	public static void main(String[] args) throws IOException {
		Properties p = new Properties();
		InputStream in = App.class.getClassLoader().getResourceAsStream(
				"reaper.properties");
		p.load(in);
		ReaperFactory<TaskData> rf = new ReaperFactory<TaskData>();
		ReaperServer<TaskData> reaperServer = rf.createReaperServer(p);

		reaperServer.setOnDataListener(new OnDataListener<TaskData>() {

			@Override
			public List<TaskData> OnDataLoad(int count) {
				log.info("OnDataLoad():" + count);
				List<TaskData> list = new ArrayList<TaskData>();
				list.add(new TaskData());
				return list;
			}

			@Override
			public void OnDataEnd(List<TaskData> list) {
				log.info("OnDataEnd()");
			}
		});
		reaperServer.setOnTaskListener(new OnTaskListener<TaskData>() {
			@Override
			public OnTaskListener<TaskData> NewTask() {
				log.info("OnTaskInit()");
				return this;
			}

			@Override
			public void OnTaskProcess(TaskData tdp) {
				log.info("OnTaskProcess()");
			}
		});
		reaperServer.setOnAutoListener(new OnAutoListener<TaskData>() {
			@Override
			public OnAutoListener<TaskData> NewTask() {
				log.info("OnTaskInit()");
				return this;
			}

			@Override
			public void OnTaskProcess(TaskData tdp) {
				log.info("OnTaskProcess()");
			}

			@Override
			public List<TaskData> OnDataLoad(int count) {
				log.info("OnDataLoad():" + count);
				List<TaskData> list = new ArrayList<TaskData>();
				list.add(new TaskData());
				return list;
			}

			@Override
			public void OnDataEnd(List<TaskData> list) {
				log.info("OnDataEnd()");

			}
		});
		try {
			reaperServer.start();
		} catch (ReaperException e) {
			log.error("start error", e);
		}
	}
}
